package com.xjh.basestudy.designmode.createMode.createMode2_Prototype.p3_DeepClone;

import lombok.Getter;
import lombok.Setter;

/**
 * @Author XuJianHua
 * @Date 2022/9/24 11:52
 * @Description
 * 首先我们在第13行的克隆方法clone()中依旧对敌机对象进行了克隆操作，紧接着对敌机子弹bullet也进行了克隆，这就是深拷贝操作。当然，此处要注意对于子弹类Bullet同样也得实现克隆接口
 */
public class EnemyPlaneDeep implements Cloneable{
    // 这里的bullet也必须实现克隆接口及克隆方法，才能深拷贝
    @Setter
    @Getter
    private BulletDeep bulletDeep;
    private int x;//敌机横坐标
    private int y = 0;//敌机纵坐标

    public EnemyPlaneDeep(int x, BulletDeep bulletDeep) {
        this.x = x;
        this.bulletDeep = bulletDeep;
    }

    @Override
    protected EnemyPlaneDeep clone() throws CloneNotSupportedException {
        EnemyPlaneDeep clonePlane = (EnemyPlaneDeep) super.clone();//克隆出敌机
        clonePlane.setBulletDeep(this.bulletDeep.clone());//对子弹进行深拷贝
        return clonePlane;
    }

    //之后代码省略……

}